package com.markchu.modules.system.repository;


import com.markchu.modules.system.domain.Chats;
import com.markchu.modules.system.domain.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author mark_chu
 * @date 2023/12/08
 */
//public interface ChatsRepository extends BaseRepository<Chats, Long> {
public interface ChatsRepository extends BaseRepository<Chats, Long>, JpaSpecificationExecutor<Chats> {
    @Query(value="SELECT distinct to_user_id FROM web_chats x where (x.from_user_id  = ?1 and x.to_user_id!= ?1)",nativeQuery = true)
    List<Long> findAllFromUserIds(Long fromUserId);

    @Query(value="SELECT distinct from_user_id FROM web_chats x where (x.to_user_id  = ?1 and x.from_user_id!= ?1)",nativeQuery = true)
    List<Long> findAllToUserIds(Long toUserId);
    @Query(value="SELECT * FROM web_chats x where x.from_and_to  = ?1 and x.create_date > ?2 order by x.create_date asc limit ?3,?4",nativeQuery = true)
    List<Chats> getAllDatas(Long  fromAndTo, String createDate,Long offset,Integer pageSize);
}